package com.api.shopapi.mapper;

import com.api.shopapi.entity.ElderlyCheckinAssessItem;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface ElderlyCheckinAssessItemMapper {
    @Insert("insert into elderly_checkin_assess_item " +
            "(ElderlyCheckinAssessItemCode,ElderlyCheckinAssessCode,CheckinAssessGroupCode,CheckinAssessGroupName,CheckinAssessItemCode,CheckinAssessItemName,Fraction,CheckinAssessClassCode,CheckinAssessClassName) " +
            "value(#{elderlyCheckinAssessItem.ElderlyCheckinAssessItemCode},#{elderlyCheckinAssessItem.ElderlyCheckinAssessCode}," +
            "#{elderlyCheckinAssessItem.CheckinAssessGroupCode},#{elderlyCheckinAssessItem.CheckinAssessGroupName},#{elderlyCheckinAssessItem.CheckinAssessItemCode}," +
            "#{elderlyCheckinAssessItem.CheckinAssessItemName},#{elderlyCheckinAssessItem.Fraction},#{elderlyCheckinAssessItem.CheckinAssessClassCode},#{elderlyCheckinAssessItem.CheckinAssessClassName})")
    int insert(@Param("elderlyCheckinAssessItem") ElderlyCheckinAssessItem elderlyCheckinAssessItem);

    @Delete("delete from elderly_checkin_assess_item where ElderlyCheckinAssessItemCode=#{elderlyCheckinAssessItemCode}")
    int deleteByElderlyCheckinAssessItemCode(@Param("elderlyCheckinAssessItemCode") String elderlyCheckinAssessItemCode);

    @Update("update elderly_checkin_assess_item set ElderlyCheckinAssessCode = #{elderlyCheckinAssessItem.ElderlyCheckinAssessCode},CheckinAssessGroupCode=#{elderlyCheckinAssessItem.CheckinAssessGroupCode}," +
            "CheckinAssessGroupName=#{elderlyCheckinAssessItem.CheckinAssessGroupName},CheckinAssessItemCode=#{elderlyCheckinAssessItem.CheckinAssessItemCode}," +
            "CheckinAssessItemName=#{elderlyCheckinAssessItem.CheckinAssessItemName},Fraction=#{elderlyCheckinAssessItem.Fraction},CheckinAssessClassCode=#{elderlyCheckinAssessItem.CheckinAssessClassCode},CheckinAssessClassName=#{elderlyCheckinAssessItem.CheckinAssessClassName} " +
            "where ElderlyCheckinAssessItemCode=#{elderlyCheckinAssessItem.ElderlyCheckinAssessItemCode}")
    int updateByElderlyCheckinAssessItemCode(@Param("elderlyCheckinAssessItem") ElderlyCheckinAssessItem elderlyCheckinAssessItem);


    @Select("select * from elderly_checkin_assess_item where ElderlyCheckinAssessItemCode=#{elderlyCheckinAssessItemCode} limit 1")
    ElderlyCheckinAssessItem getByElderlyCheckinAssessItemCode(@Param("elderlyCheckinAssessItemCode") String elderlyCheckinAssessItemCode);

    @Delete("delete from elderly_checkin_assess_item where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode}")
    int deleteByElderlyCheckinAssessCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode);

    @Select("select * from elderly_checkin_assess_item where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode} order by CheckinAssessClassCode")
    List<ElderlyCheckinAssessItem> getByElderlyCheckinAssessCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode);

    @Select("select * from elderly_checkin_assess_item where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode} group by CheckinAssessClassCode")
    List<ElderlyCheckinAssessItem> getByElderlyCheckinAssessCodeGroupByCheckinAssessClassCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode);

    @Select("select * from elderly_checkin_assess_item where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode} and CheckinAssessClassCode=#{checkinAssessClassCode}")
    List<ElderlyCheckinAssessItem> getByElderlyCheckinAssessCodeAndCheckinAssessClassCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode,@Param("checkinAssessClassCode") String checkinAssessClassCode);
}
